package cn.fengzhilun.javase.day14.day09;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

public class TestScore {
	@Test
	public void test1() throws IOException {
		Map<String,List<Score>> scores = new HashMap<>();
		
		List<String> list = Files.readAllLines(Paths.get("data/scores.csv"));
		
		for(String line : list) {
			String [] data = line.split(",");
			
			String name = data[0];
			String course = data[1];
			double score = Double.parseDouble(data[2]);
			
			if(scores.containsKey(name)) {
				List<Score> scoreByStudent = scores.get(name);
				scoreByStudent.add(new Score(score , name , course));
				
			}else {
				List<Score> scoreByStudent = new ArrayList<>();
				
				scoreByStudent.add(new Score(score,name, course));
				
				scores.put(name, scoreByStudent);
			}
		}
		System.out.println(scores.get("张三"));
	}
	@Test
	public void test2() throws IOException {
		List<String> list = Files.readAllLines(Paths.get("data/scores.csv"));
		
		Map<String, Map<String,Score>> scores = new HashMap<>();
		
		for(String line : list) {
			String[] data = line.split(",");
			String name = data[0];
			String course = data[1];
			double score = Double.parseDouble(data[2]);
			
			if(scores.containsKey(name)) {
				Map<String, Score> map = scores.get(name);
				map.put(course, new Score(score, course, name));
			}else {
				Map<String,Score> scoreByCourse = new HashMap<>();
				scoreByCourse.put(course, new Score(score, course, name));
				
				scores.put(name, scoreByCourse);
			}
		}
		//System.out.println(scores.get("张三").get("语文"));
	}
	@Test
	public void test3() {
		Map<Character, Integer> map = new HashMap<>();
		
		map.put('j', 10);
		
		System.out.println(map);
	}
	@Test
	public void test4() {
		String str = "My name is zhang , I like speak chinese";
		
		int[] counts = new int[26];
		
		for(int i = 0 ;i < str.length();i++) {
			
			char c = str.charAt(i);
			
			boolean isUpperCase = ('A' <= c && c <= 'Z');
			boolean isLowerCase = ('a' <= c && c <= 'z');
			boolean isLetter = isUpperCase || isLowerCase;
			
			if(!isLetter) {
				continue;
			}
			
			if(isUpperCase) {
				c = (char) (c+32);
				int index = (c-'a');
				counts[index]++;
			}else {
				int index = (c-'a');
				counts[index]++;
			}
		}
		System.out.println(Arrays.toString(counts));
	}
	@Test
	public void test() {
		List<Integer> list = new ArrayList<>();
		for(int i = 1; i<=10; i++) {
			list.add(i);
		}
		while(list.size() > 0) {
			int index = (int) (Math.random()*list.size());
			Integer remove = list.remove(index);
			
			System.out.println(remove);
		}
	}
}
